<?php
	
	function mark($grade,$scheme_id)
	{
		$query = "SELECT * FROM block WHERE scheme_id  = '$scheme_id'";
		$mark_query = mysql_query($query) or die(mysql_error());
		$count = 0;
		$limit = mysql_num_rows($mark_query);
		while($count < $limit)
		{
			mysql_data_seek($mark_query, $count);
			$block = mysql_fetch_array($mark_query);
			$cond_down = $block['lower_condition'];
			$cond_up = $block['upper_condition'];
			$bound_down = $block['lower_bound'];
			$bound_up = $block['upper_bound'];
			$mark = $block["mark"];
			if(test($cond_down,$bound_down,$bound_up,$cond_up,$grade))
			{
				return $mark;
			}
			$count++;
		}
		
	}

	function test($low_cd,$low_bd,$high_bd,$high_cd,$val)
	{
		if (($low_cd=='(') && ($high_cd==')'))
		{
			if (($low_bd<$val) && ($high_bd>$val))
			{return true;}
			return false;
		}

		if (($low_cd=='[') && ($high_cd==')'))
		{
			if (($low_bd<=$val) && ($high_bd>$val))
			{return true;}
			return false;
		}
		
		if (($low_cd=='(') && ($high_cd==']'))
		{
			if (($low_bd<$val) && ($high_bd>=$val))
			{return true;}
			return false;
		}
		
		if (($low_cd=='[') && ($high_cd==']'))
		{
			if (($low_bd<=$val) && ($high_bd>=$val))
			{return true;}
			return false;
		}
		
		return false;
	}
?>
